package com.example.designpattern.creator.builder;

/**
 * Separate the construction of a complex object from its representation so that the same construction process can create different representations.
 * Class have only Getter merthod, NO Setter method --> Using to create immutable instance. So all propeties is in final state.
 *
 */
public class User {

	private String firstName;
	private String lastName;
	private String address;
	private String email;
	private String phoneNumber;
	
	
	public User(UserBuilder builder) {
		this.firstName = builder.firstName;
		this.lastName = builder.lastName;
		this.address = builder.address;
		this.email = builder.email;
		this.phoneNumber = builder.phoneNumber;
	}
	
	
	public static class UserBuilder {

		private String firstName;
		private String lastName;
		private String address;
		private String email;
		private String phoneNumber;

	    public UserBuilder(String firstName, String lastName) {
	        this.firstName = firstName;
	        this.lastName = lastName;
	    }
	    public UserBuilder email(String email) {
	        this.email = email;
	        return this;
	    }
	    public UserBuilder phoneNumber(String phoneNumber) {
	        this.phoneNumber = phoneNumber;
	        return this;
	    }
	    public UserBuilder address(String address) {
	        this.address = address;
	        return this;
	    }
	    //Return the finally consrcuted User object
	    public User build() {
	        User user =  new User(this);
	        validateUserObject(user);
	        return user;
	    }
	    private void validateUserObject(User user) {
	        //Do some basic validations to check 
	        //if user object does not break any assumption of system
	    }
	}
	
	public String getFirstName() {
		return firstName;
	}
	public String getLastName() {
		return lastName;
	}
	public String getAddress() {
		return address;
	}
	public String getEmail() {
		return email;
	}
	public String getPhoneNumber() {
		return phoneNumber;
	}
	
}
